package br.com.admin.controller;

import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

import br.com.commons.utility.Attibute;
import br.com.commons.utility.exception.AppControllerException;
import br.com.commons.utility.exception.AppValidatorException;
import br.com.commons.utility.message.Message;
import br.com.commons.utility.message.TypeMessage;

public class BaseController {
	
	@ExceptionHandler(value={AppControllerException.class})
	public @ResponseBody String exception(AppControllerException exception){
		Attibute attributes = new Attibute();
		attributes.addAttributes("messages", new Message(TypeMessage.ERROR, exception.getMessage()));		
		return attributes.getJsonByAttribute();	
	}
	
	@ExceptionHandler(value={AppValidatorException.class})
	public @ResponseBody String exception(AppValidatorException exception){	
		Attibute attributes = new Attibute();
		attributes.addAttributes("messages", exception.getMessages());
		return attributes.getJsonByAttribute();	
	}
}
